﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace DDD4Fun.State
{
    public class SoldState : IState
    {
         MyStateMachine machine;

         public SoldState(MyStateMachine machine)
        {
            this.machine = machine;
        }

        #region IState Members

        public void InsertQuarter()
        {
            Console.WriteLine("等一下啊，正在出糖果");
        }

        public void EjectQuarter()
        {
            Console.WriteLine("你已经转动曲柄，没得退了");
        }

        public void TurnCrank()
        {
            Console.WriteLine("转多少次都只有一个糖果");
        }

        public void Dispense()
        {
            machine.ReleaseBall();
            if (machine.GetCount() > 0)
            {
                machine.SetState(machine.GetNoQuarterState());
            }
            else
            {
                Console.WriteLine("糖果卖光了！");
                machine.SetState(machine.GetSoldOutState());
            }
        }

        #endregion
    }
}
